#include <cstdio>
#include <cstring>

int n;
long long c1[ 100001 ], c2[ 100001 ];

int lowbit( int t ) { return t & ( t ^ ( t - 1 ) ); }

long long sum( long long *c, int x )
{
    long long ret = 0;
    while ( x )
    {
        ret += c[ x ];
        x -= lowbit( x );
    }
    return ret;
}

void add( long long *c, int x, int p )
{
    while ( x <= 100000 )
    {
        c[ x ] += p;
        x += lowbit( x );
    }
}

int main( )
{
    int i, u, t;
    long long ans;
    while ( scanf("%d", &n) != EOF )
    {
        memset( c1, 0, sizeof( c1 ) );
        memset( c2, 0, sizeof( c2 ) );
        ans = 0;
        for ( i = 1; i <= n; i++ )
        {
            scanf("%d", &u);
            ans += sum( c2, 100000 - u + 1 ) * u + sum( c1, 100000 - u + 1 );
            add( c1, 100000 - u + 1, u );
            add( c2, 100000 - u + 1, 1 );
        }
        printf("%I64d\n", ans);
    }
    return 0;
}
